feat: load editable api console bodies - #31
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an “editable load” workflow to the API Console so users can fetch an existing Admin API resource, automatically strip top-level read-only fields from the JSON, and optionally restore the original raw response body.
Changes:
- Load an existing resource response into the request editor as an editable body (with read-only keys stripped and JSON keys normalized for readability).
- Show an informational notice listing removed read-only fields and provide a “Use raw response” restore action.
- Add Playwright E2E coverage for loading a GET route into an editable PUT-style body and restoring the raw response.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/routes/raw_api/index.tsx |
Implements editable-body loading, removed-keys notice UI, and raw-response restore behavior in the API Console. |
src/routes/raw_api/index.module.css |
Styles the new loaded-body alert spacing. |
e2e/tests/api-console.spec.ts |
Adds E2E coverage validating stripped read-only fields and the raw-restore action. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const editableBody = getEditableLoadedBody(value); | ||
| setBody(editableBody.body); | ||
| setLoadedBodyNotice( | ||
| editableBody.removedKeys.length > 0 | ||
| ? { |
| onChange={(nextValue) => { | ||
| setBody(nextValue ?? ''); | ||
| setLoadedBodyNotice(null); | ||
| }} |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7909e212d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }; | ||
| } | ||
|
|
||
| const editableValue = stripPatchReadonlyFields(value); |
There was a problem hiding this comment.
Don't strip consumer usernames from loaded bodies
When the selected resource is Consumers, value contains the required top-level username, but this generic sanitizer removes it via PATCH_READONLY_KEYS. APISIX.ConsumerPut still requires username and the normal consumer PUT wrapper preserves it in the payload (src/types/schema/apisix/consumers.ts:24-39, src/apis/consumers.ts:44-48), so loading a consumer and sending the generated PUT body will fail Admin API validation instead of providing an editable update body.
Useful? React with 👍 / 👎.
| }; | ||
| } | ||
|
|
||
| const editableValue = stripPatchReadonlyFields(value); |
There was a problem hiding this comment.
Strip SSL validity fields from loaded bodies
For SSL resources, Admin API responses can include generated validity_start/validity_end fields (the SSL list reads validity_end), and the normal SSL write path explicitly deletes both before PUT (src/apis/ssls.ts:27-30). Because the new loader only removes PATCH_READONLY_KEYS, loading an SSL leaves those generated fields in the editable request body, so sending the unchanged loaded body through API Console includes fields that the regular API wrapper already treats as read-only.
Useful? React with 👍 / 👎.
Summary
Verification